package com.esd.device.controller;

import com.esd.common.pojo.R;
import com.esd.device.entity.Line;
import com.esd.device.entity.vo.LineData;
import com.esd.device.service.LineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("line")
public class LineController {

    @Autowired
    private LineService lineService;

    @GetMapping("listAllViewOn")
    public R listAllViewOn(){
        return R.ok(lineService.listAllViewOn());
    }

    @GetMapping("listAll")
    public R listAll(){
        return R.ok(lineService.list());
    }

    @GetMapping("getById/{lineId}")
    public R getById(@PathVariable Long lineId){
        return R.ok(lineService.getById(lineId));
    }

    @PostMapping("addLine")
    public R addLine(@RequestBody Line line){
        return lineService.addLine(line) ;
    }

    @PutMapping("updateLine")
    public R updateLine(@RequestBody Line line){
        return lineService.updateLine(line) ;
    }

    @DeleteMapping("deleteLine/{lineId}")
    public R deleteLine(@PathVariable Long lineId){
        return lineService.deleteById(lineId);
    }

    @PostMapping("saveModule")
    public R saveModule(@RequestBody Map<String , String> params){
        return lineService.saveModule(params);
    }

    @GetMapping("getModule")
    public R getModule(@RequestParam(name = "lineName") String lineName){
        return lineService.getModule(lineName) ;
    }

    @GetMapping("getModuleImages")
    public R getModuleImages(){
        return lineService.getModuleImages();
    }

    @GetMapping("getPositions")
    public R getPositions(@RequestParam(name = "lineName") String lineName){
        return lineService.getPositions(lineName) ;
    }

    @PostMapping("savePositions")
    public R savePositions(@RequestBody Map<String , String> params){
        return lineService.savePositions(params);
    }

    @GetMapping("getCurrentStatus")
    public R getCurrentStatus(@RequestParam(name = "lineName") String lineName){
        return lineService.getCurrentStatus(lineName) ;
    }

    @GetMapping("getLogoPath")
    public String getLogoPath(){
        return "/images/module/" + "logo.png" ;
    }

    @GetMapping("getLineCount")
    public R getLineCount(){
        return lineService.getLineCount();
    }

    @GetMapping("getLineDataList")
    public List<List<LineData>> getLineDataList(){
        return lineService.getLineDataList();
    }

    @Value("${dashboard.page_size}")
    private int page_size ;

    @GetMapping("getPageSize")
    public int getPageSize(){
        return page_size ;
    }

    @GetMapping("/setViewOn/{lineId}/{value}")
    public R setViewOn(
            @PathVariable Long lineId,
            @PathVariable String value
    ){
        return lineService.setViewOn(lineId , value) ;
    }
}
